'use strict';
app.controller('fullReductionCtrl', ['$scope', 'utilService', '$filter', '$modal', function ($scope, utilService, $filter, $modal) {
    $scope.fullReductionListVO = {
        status: -1
    }
    //查询所有满减活动
    $scope.findAll = function () {
        if ($scope.fullReductionListVO.status == -1) {
            $scope.fullReductionListVO.status = ""
        }
        $scope.fullReductionListVO.startTime = $filter('date')($scope.fullReductionListVO.startTime, 'yyyy-MM-dd'),
        $scope.fullReductionListVO.endTime = $filter('date')($scope.fullReductionListVO.endTime, 'yyyy-MM-dd'),
        utilService.queryForPagingList($scope, {
            url: $scope.app.domain + "full/reduction",
            params: $scope.fullReductionListVO
        }).then(function (rlt) {
        });
    }
    $scope.findAll();
    $scope.changeStatus = function (status) {
        $scope.fullReductionListVO.status = status;
        $scope.findAll();
    }
    //删除满减活动
    $scope.fullReductionDelete = function (id, name) {
        openModal("你是否要删除[" + name + "]满减活动？删除后将无法恢复");
        function openModal(msg) {
            utilService.modal($modal, $scope, {
                title: "删除满减活动",
                controller: "deleteFullReductionCtrl",
                message: msg,
                data: id
            });
        }
    }
}]);
app.controller('deleteFullReductionCtrl', ['$scope', '$modalInstance', '$state', 'fullReductionService', 'toaster', 'modalData',
    function ($scope, $modalInstance, $state, fullReductionService, toaster, modalData) {
        $scope.modal = modalData;
        $scope.fullReduction = {
            id: modalData.data
        };
        $scope.isDelModal = true;
        //确认删除
        $scope.ok = function () {
            if (!$scope.isDelModal) {
                return;
            }
            $scope.isDelModal = false;

            fullReductionService.delete($scope).then(function (result) {
                switch (result.status) {
                    case 200:
                        $modalInstance.dismiss('success');
                        $state.reload();
                        toaster.pop('success', "提示", "操作成功");
                        break;
                    default :
                        toaster.pop('error', "操作失败", "发生未知错误！请联系管理员");
                        break;
                }
            });
        }

        //取消弹窗
        $scope.cancel = function () {
            $modalInstance.dismiss('cancel');
        };
    }
]);